package com.qf.fmall2202.order.controller;

import com.qf.fmall2202.order.entity.Orders;
import com.qf.fmall2202.order.service.OrdersService;
import com.qf.fmall2202.vo.ResultVo;
import com.qf.fmall2202.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单  前端控制器
 * </p>
 *
 * @author 徐英海
 * @since 2022-11-09
 */
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/add")
    public ResultVo add(@RequestParam("cids") String cids, @RequestBody Orders orders) {
        return ordersService.addOrders(cids, orders);
    }

    @GetMapping("/status/{orderId}")
    public String status(@PathVariable("orderId") String orderId) {
        return ordersService.status(orderId);
    }

    /**
     * 模拟微信支付回调接口
     *
     * @param oid
     * @return
     */
    @GetMapping("/callback")
    public ResultVo payCallBack(String oid) {
        //当接口被调用时，订单支付成功
        WebSocketServer.sendMsg(oid, "1");
        return ResultVo.ok();
    }
}
